//
//  ASHomeMainModel.m
//  AvatarShow
//
//  Created by xunruiIOS on 2021/4/27.
//

#import "ASHomeMainModel.h"

@implementation ASHomeMainModel

- (void)encodeWithCoder:(NSCoder *)coder
{
    unsigned int count = 0;
    Ivar * ivars = class_copyIvarList([self class], &count);
    for (int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];
        const char * name = ivar_getName(ivar);
        NSString * key = [NSString stringWithUTF8String:name];
        //kvc 获取属性的值
        id value = [self valueForKey:key];
        
        //归档!!
        [coder encodeObject:value forKey:key];
    }
    free(ivars);
}

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super init];
    if (self) {
        unsigned int count = 0;
        Ivar * ivars = class_copyIvarList([self class], &count);
        for (int i = 0; i < count; i++) {
            Ivar ivar = ivars[i];
            const char * name = ivar_getName(ivar);
            NSString * key = [NSString stringWithUTF8String:name];
            //解档
            id value = [coder decodeObjectForKey:key];
            //设置到属性上面  kvc
            if (value) {
                [self setValue:value forKey:key];
            }
        }
        free(ivars);
    }
    return self;
}

+ (NSDictionary *)modelCustomPropertyMapper {
    return @{
                @"tID":@"id",
                @"descriptionStr":@"description",
             };
}

- (CGFloat)groupCellH{
    if (_groupCellH < 10) {
        CGFloat tagH = 0;
        if (self.tag_arr.count > 0) {
            tagH = 40;
        }
        _groupCellH = 83 + self.groupImageH + tagH + 15 + 30 + 15 + 5;
    }
    return _groupCellH;
}

- (CGFloat)groupImageH{
    if (_groupImageH < 10) {
        CGFloat w = (SCREEN_WIDTH - 28 - 10)/3;
        _groupImageH = w * 3 + 10;
    }
    return _groupImageH;
}
@end
